package qianting.news.article.controller;

import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import qianting.news.apis.models.article.dtos.ArticleHomeDto;
import qianting.news.article.service.ApArticleService;
import qianting.news.common.constant.ArticleConstants;
import qianting.news.common.entity.State;

@Api(tags = "文章首页管理")
@RestController
@RequestMapping("/")
public class ArticleHomeController {

    @Autowired
    private ApArticleService apArticleService;

    //TODO 加入缓存CacheService
    @PostMapping("/load")
    public State load(@RequestBody ArticleHomeDto dto) {
//        return apArticleService.load(ArticleConstants.LOADTYPE_LOAD_MORE,dto);
        return apArticleService.load2(ArticleConstants.LOADTYPE_LOAD_MORE,dto,true);//true表示默认是首页
    }

    @PostMapping("/loadmore")
    public State loadMore(@RequestBody ArticleHomeDto dto) {
        return apArticleService.load(ArticleConstants.LOADTYPE_LOAD_MORE,dto);
    }

    @PostMapping("/loadnew")
    public State loadNew(@RequestBody ArticleHomeDto dto) {
        return apArticleService.load(ArticleConstants.LOADTYPE_LOAD_NEW,dto);
    }
}
